<template>
  <div class="app-container">
    <el-dialog :title="pageTitle" :visible.sync="dialogFormVisible" :before-close="beforeClose" width="50%">

      <el-form class="demo-form-inline">

        <el-form-item label="转出方" :label-width="formLabelWidth">
          <el-select v-model="value" placeholder="请选择转出的项目" @change="change">
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
       </el-form-item>
        <el-form-item label="转出金额" :label-width="formLabelWidth">
          <el-input v-model="amount" :disabled="isFund == true ? false : true" width="25%"></el-input>
        </el-form-item>
        <el-form-item label="转给用户" :label-width="formLabelWidth" v-show="isFund">
          <el-input v-model="user_id" width="25%"></el-input>
        </el-form-item>
        <el-form-item label="转出说明" :label-width="formLabelWidth" v-show="isFund">
          <el-input v-model="reason" width="25%"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="canel">取 消</el-button>
        <el-button @click="sure()">确 认</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { Message } from 'element-ui'
import { transferList } from '@/api/member'
import { transferHandle } from '@/api/member'
export default {
  name: 'TransferHandle',
  data() {
    return {
      value: '',
      dialogFormVisible: false,
      pageTitle: '剩余金额转入教育基金',
      placeHolderReason: '剩余金额',
      options: [{
          value: '1',
          label: '虹包'
        },{
          value: '2',
          label: '报单奖励'
        }, {
          value: '3',
          label: '分虹'
        }, {
          value: '4',
          label: '招商奖励'
        }, {
          value: '5',
          label: '教育培训基金'
        }],
        formLabelWidth: '120px',
        amount:'',
        storeId:'',
        isFund:false,//教育基金转出为true
        user_id:'',//教育基金转向用户
        reason:'',//教育基金转向用户说明
    }
  },

  methods: {
    beforeClose() {
      this.canel()
    },
    canel() {
      this.dialogFormVisible = false
    },

    handle(storeId) {
      this.dialogFormVisible = true
      this.storeId = storeId
    },
    change(id){
      this.isFund = false
      if(id == 5){
        this.isFund = true
      }
      transferList({type:id,storeId:this.storeId}).then(response => {
        console.log(response)
        this.amount = response.data
      })
    },
    sure() {
      transferHandle({type:this.value,storeId:this.storeId,user_id:this.user_id,reason:this.reason,amount:this.amount}).then(res => {
        Message.success('操作成功')
        this.$emit('afterSave')
        this.canel()
      })
    }
  }
}
</script>
